package com.iemes.controller.mould;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.iemes.annotation.SystemLog;
import com.iemes.controller.index.BaseController;
import com.iemes.entity.DevelopJudgeFormMap;
import com.iemes.entity.DevelopProgressFormMap;
import com.iemes.entity.SurfaceCheckFormMap;
import com.iemes.entity.UserFormMap;
import com.iemes.mapper.mould.DevelopProgressMapper;
import com.iemes.mapper.mould.SurfaceCheckMapper;
import com.iemes.plugin.PageView;
import com.iemes.util.Common;

@RequestMapping("/developProgress/")
@Controller
public class DevelopProgressController extends BaseController {

	@Inject
	private DevelopProgressMapper developProgressMapper;
	
	@RequestMapping("developProgress_list")
	public String examineOrder(Model model){
		model.addAttribute("res", findByRes());
		return Common.BACKGROUND_PATH + "/mould/developProgress/developProgress_list";
	}
	
	@ResponseBody
	@RequestMapping("developProgress_findByPage")
	public PageView findByPage(String pageNow, String pageSize) throws Exception 
	{
		DevelopProgressFormMap developProgressFormMap = getFormMap(DevelopProgressFormMap.class);
		List<Map<String, Object>> developProgress = developProgressMapper.getAll(developProgressFormMap);
		LuogicPaging(pageNow, pageSize, developProgress);
		return pageView;
	}
	
	@RequestMapping("developProgress_edit")
	public String editUI(Model model) throws Exception {
		String id = getPara("id");
		if(Common.isNotEmpty(id)){
			//根据id查询模具开发进度跟踪表
			DevelopProgressFormMap progress=developProgressMapper.getById(id);
			model.addAttribute("progress",progress);
		}
		return Common.BACKGROUND_PATH + "/mould/developProgress/developProgress_edit";
	}
	
	@ResponseBody
	@RequestMapping(value="developProgress_editEntity")
	@Transactional(readOnly=false)//需要事务操作必须加入此注解
	@SystemLog(module="新开模开发申请",methods="模具开发进度跟踪表-编辑模具开发进度跟踪表")//凡需要处理业务逻辑的.都需要记录操作日志
	public String editEntity(HttpServletRequest request) throws Exception {
		DevelopProgressFormMap developProgressFormMap = getFormMap(DevelopProgressFormMap.class);
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
		Date date=new Date();
		// 获取request
		request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();  
		// 通过工具类获取当前登录的bean
		UserFormMap userFormMap = (UserFormMap)Common.findUserSession(request);
		developProgressFormMap.put("date", sdf.format(date));
		developProgressFormMap.put("fillPeopleId", userFormMap.getInt("id"));
		baseMapper.editEntity(developProgressFormMap);
		return "success";
	}
}









